---
import { cachedFetch } from '../util-server';

export interface Props {
	pkgName: string;
}

const { pkgName } = Astro.props as Props;

const url = `https://registry.npmjs.org/${pkgName}/latest`;

const response = await cachedFetch(url);
const json = await response.json();

if (!response.ok) {
	throw new Error(
		`npm API call failed: GET "${url}" returned status ${response.status}: ${JSON.stringify(json)}`
	);
}
---

<span>v{json.version}</span>
